home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-19 | 3.3 KB | 120 lines | [TEXT/CWIE] |
- // FileCopier.cp
-
- #ifndef FileCopier_h
- #include "FileCopier.h"
- #endif
-
- FileCopier::FileCopier()
- : sequence( *this ),
- pipe( Data( buffer + 4096 - uint32(buffer)%4096,
- sizeof(buffer) - 4096 ) )
- {
- }
-
- Task *FileCopier::operator()( const FSSpec& source,
- const FSSpec& destination )
- {
- sourceFile = &source;
- destinationFile = &destination;
- dataCopied = 0;
- info.hFileInfo.ioFlLgLen = 0;
- info.hFileInfo.ioFlRLgLen = 0;
- return sequence.Start( Step( 0, &FileCopier::CreateDestination ) );
- }
-
- TaskStep<FileCopier> FileCopier::CreateDestination( bool, DeferredTaskTime )
- {
- return Step( create( *destinationFile ), &FileCopier::GetSourceInfo );
- }
-
- TaskStep<FileCopier> FileCopier::GetSourceInfo( bool, DeferredTaskTime )
- {
- return Step( info.Get( *sourceFile ), &FileCopier::SetDestinationInfo );
- }
-
- TaskStep<FileCopier> FileCopier::SetDestinationInfo( bool, DeferredTaskTime )
- {
- return Step( info.Set( *destinationFile ), &FileCopier::OpenDestinationData );
- }
-
- TaskStep<FileCopier> FileCopier::OpenDestinationData( bool, DeferredTaskTime )
- {
- if ( info.hFileInfo.ioFlLgLen == 0 )
- return Step( 0, &FileCopier::OpenDestinationResources );
-
- return Step( open.OpenDataFork( *destinationFile, destinationPath ),
- &FileCopier::OpenSourceData );
- }
-
- TaskStep<FileCopier> FileCopier::OpenSourceData( bool, DeferredTaskTime )
- {
- return Step( open.OpenDataFork( *sourceFile, sourcePath ),
- &FileCopier::CopyData );
- }
-
- TaskStep<FileCopier> FileCopier::CopyData( bool, DeferredTaskTime )
- {
- pipe.Reset();
- outStream.SetFile( destinationPath );
- inStream.SetFile( sourcePath );
-
- inStream.SuggestNoCaching();
- outStream.SuggestNoCaching();
-
- return Step( race( pumpIn( inStream, pipe.In() ),
- pumpOut( pipe.Out(), outStream ),
- 1 ),
- &FileCopier::CloseSourceData );
- }
-
- TaskStep<FileCopier> FileCopier::CloseSourceData( bool, DeferredTaskTime )
- {
- return Step( close( sourcePath ), &FileCopier::CloseDestinationData );
- }
-
- TaskStep<FileCopier> FileCopier::CloseDestinationData( bool, DeferredTaskTime )
- {
- return Step( close( destinationPath ), &FileCopier::OpenDestinationResources );
- }
-
- TaskStep<FileCopier> FileCopier::OpenDestinationResources( bool, DeferredTaskTime )
- {
- if ( info.hFileInfo.ioFlRLgLen == 0 )
- return Step( 0 );
-
- return Step( open.OpenResourceFork( *destinationFile, destinationPath ),
- &FileCopier::OpenSourceResources );
- }
-
- TaskStep<FileCopier> FileCopier::OpenSourceResources( bool, DeferredTaskTime )
- {
- return Step( open.OpenResourceFork( *sourceFile, sourcePath ),
- &FileCopier::CopyResources );
- }
-
- TaskStep<FileCopier> FileCopier::CopyResources( bool, DeferredTaskTime )
- {
- pipe.Reset();
- dataCopied = info.hFileInfo.ioFlLgLen;
- outStream.SetFile( destinationPath );
- inStream.SetFile( sourcePath );
-
- inStream.SuggestNoCaching();
- outStream.SuggestNoCaching();
-
- return Step( race( pumpIn( inStream, pipe.In() ),
- pumpOut( pipe.Out(), outStream ),
- 1 ),
- &FileCopier::CloseSourceResources );
- }
-
- TaskStep<FileCopier> FileCopier::CloseSourceResources( bool, DeferredTaskTime )
- {
- return Step( close( sourcePath ), &FileCopier::CloseDestinationResources );
- }
-
- TaskStep<FileCopier> FileCopier::CloseDestinationResources( bool, DeferredTaskTime )
- {
- return Step( close( destinationPath ) );
- }
-